<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ page contentType="text/html;charset=UTF-8" import="java.io.File" language="java"%>
<!DOCTYPE html>
<html>
<head>
<title>下载已上传的文件</title>
</head>
<body>
  <%
    File file = new File(request.getServletContext().getRealPath("/uploaded"));
    pageContext.setAttribute("file", file);
  %>
  <div align="center">
    <a href="<c:out value='${pageContext.servletContext.contextPath}/upload' escapeXml='fasle' />">上传文件</a>
    <c:set var="error" value="${requestScope.error}" scope="request" />
    <c:if test="${error != null && error != ''}">
      <c:out value="${error}" />
    </c:if>
    <c:set var="files" scope="page" value="${pageScope.file.listFiles()}" />
    <c:if test="${files != null && fn:length(files) > 0}">
      <c:out value="<table border='1' style='width: 75%; border-collapse: collapse'>" escapeXml="false" />
      <c:out value="<tr>" escapeXml="false" />
      <c:out value="<th>文件名</th>" escapeXml="false" />
      <c:out value="<th>文件长度</th>" escapeXml="false" />
      <c:out value="</tr>" escapeXml="false" />
      <c:forEach var="file" items="${files}">
        <c:out value="<tr>" escapeXml="false" />
        <c:out value="<td><a href='${pageContext.servletContext.contextPath}/download/${file.name}'>${file.name}</a></td>" escapeXml="false" />
        <c:out value="<td>${file.length()}</td>" escapeXml="false" />
        <c:out value="</tr>" escapeXml="false" />
      </c:forEach>
      <c:out value="</table>" escapeXml="false" />
    </c:if>
  </div>
</body>
</html>
